﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Input;
using System.Diagnostics.Contracts;
using System.ComponentModel.Composition.Hosting;
using System.ComponentModel.Composition.Primitives;
using System.ComponentModel.Composition;
using System.Diagnostics;

namespace ShredTheLog.Common.MVVM
{
    /// <summary>
    /// Provides common functionality for ViewModel classes
    /// </summary>
    public abstract class ViewModelBase : INotifyPropertyChanged
    {
        public static CompositionContainer CompositionContainer { get; set; }

        public ViewModelBase()
        {
            var compositionContainer = CompositionContainer;
            if (compositionContainer != null)
                compositionContainer.SatisfyImportsOnce(this);
        }

        public event PropertyChangedEventHandler PropertyChanged;

        protected void OnPropertyChanged<T>(System.Linq.Expressions.Expression<Func<T>> property)
        {
            Contract.Requires(property != null);

            if (PropertyChanged != null)
            {
                PropertyChanged(this, new PropertyChangedEventArgs(Helper.GetPropertyName(property)));
            }
        }
    }
}
